import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (locker){
                System.out.println("t1 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait 之后");
            }
        });

        Thread t2 = new Thread(() -> {
            // notify 也和 wait 类似，也是放到 synchronized 内部的
            synchronized (locker){
                System.out.println("t2 notify 之前");

                Scanner sc = new Scanner(System.in);
                System.out.println("请输入任意内容 触发notify");
                sc.nextInt();

                locker.notify();
                System.out.println("t2 notify 之后");
            }
        });

        t1.start();
        t2.start();

    }
}
